<?php
session_start();
require("page.php");
$header = "";
$header = addHeader("Captcha Collection");
echo($header);

?>
<div id="menucontainer">
  <div id="menu">
  <div id="navcontainer">
  <ul id="navlist">

  </ul>
</div>
</div>
</div>
<div id="content">

  <h2>Thank You</h2>
<p> 
Thank you for playing the results will be sent via email at the end of every week.  Please feel free to play as many times as you like, the more you play the better your chance of winning a weekly prize or even the grand prize.
  </p>
<h2>Top Scores...</h2>

<?php
require('dbconnection.php');
db_connect();

$calculateScore="SELECT d1.user, count( d1.num ) * d1.numtaboowords AS score
  FROM descriptors d1, descriptors d2 
 WHERE d1.pic_number = d2.pic_number AND
 d1.user <> d2.user AND
 d1.word = d2.word
 GROUP BY d1.user
 order by  score desc
 limit 5";



$resultAnswerQuery = mysql_query($calculateScore);

if (!$resultAnswerQuery)
  throw new Exception("There was an error with the leader table");    

$length = mysql_num_rows($resultAnswerQuery);

if($length > 0){
  echo "<table>";
  echo "<tr><td><h2>Student</h2></td><td><h2>Score</h2></td></tr>\n";
  while($resultAnswer = mysql_fetch_row($resultAnswerQuery)){
    echo "<tr><td><h4>$resultAnswer[0]</h4></td><td><h4>$resultAnswer[1]<h4></td></tr>\n";
  }

  echo "</table>";
 }else{
  echo "There are currently no top goal scorers";
 }

?>
<a href='login.php' class='direct'>Play Again</a>
</div>
<?php
echo(addFooter());
unset($_SESSION['views']);
unset($_SESSION['uname']);
?>
